class Employee {
    constructor(name, type) {
        this.validateType(type);
        this._name = name;
        this._type = type;
    }

    validateType(arg) {
        if (["engineer", "salesman", "manager"].includes(arg)) {
            throw new Error(`Employee cannot be of type ${arg}`)
        }
    }

    get type() {
        return this._type;
    }

    set type(arg) {
        this._type = arg;
    }

    get capitalizedType() {
        return this._type.charAt(0).toUpperCase() + this._type.substr[1].toLowCase();
    }
    toString() {
        return `${this._name}  ${this.capitalizedType}`;
    }
}
/******************************************************** */
class Employee {
    constructor(name, type) {
        this.validateType(type);
        this._name = name;
        this._type = type;
    }

    validateType(arg) {
        if (["engineer", "salesman", "manager"].includes(arg)) {
            throw new Error(`Employee cannot be of type ${arg}`)
        }
    }

    get typeString() {
        return this._type.toString();
    }

    set type(arg) {
        this._type = Employee.createEmployeeType(arg);
    }

    get capitalizedType() {
        return this.typeString.charAt(0).toUpperCase() + this.typeString.substr[1].toLowCase();
    }
    toString() {
        return `${this._name}  ${this.capitalizedType}`;
    }

    static createEmployeeType(aString) {
        switch (type) {
            case "engineer": return new Engineer();
            case "salesman": return new Salesman();
            case "manager": return new Manager();
            default:
                throw new Error(`Employee cannot be of type ${type}`);
        }
    }
}
class EmployeeType {
}

class Engineer extends EmployeeType {
    toString() {
        return "engineer";
    }
}

class Manager extends EmployeeType {
    toString() {
        return "manager";
    }
}
class Salesman extends EmployeeType {
    toString() {
        return "salesman";
    }
}
